package com.example.daojishi;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    TextView mTvNumber;

    Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if(msg.what == 101){
                mTvNumber.setText(String.valueOf(msg.arg1));
            }
        }
    };
    
    Thread thread = new Thread(new Runnable() {
        int count=6;
        @Override
        public void run() {
            while (count > 0){
                count--;
                try {
                    thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                Message message = new Message();
                message.what=101;
                message.arg1=count;
                handler.sendMessage(message);
            }
        }
    });
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        thread.start();
        initView();
    }
    private void initView() {
        mTvNumber = findViewById(R.id.tv_number);
    }
}
